package com.cyj.springtx1.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyj.springtx1.entity.User;
import com.cyj.springtx1.mapper.IUserMapper;
import com.cyj.springtx1.service.IUserService;

/**
 * @description:
 * @Author C_Y_J
 * @create 2021-03-04 10:20
 **/
public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements IUserService {

    private IUserMapper userMapper;

    public UserServiceImpl(IUserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public void transfer() {
        //李四向张三转账500
        //update user set money= money-500 where user_name = '李四'
        UpdateWrapper<User> updateWrapper1 = new UpdateWrapper<User>().eq("user_name", "李四").set("money", "4500");
        userMapper.update(null, updateWrapper1);
        int i = 1 / 0;
        //update user set money= money+500 where user_name = '张三'
        UpdateWrapper<User> updateWrapper2 = new UpdateWrapper<User>().eq("user_name", "张三").set("money", "4500");
        userMapper.update(null, updateWrapper2);
    }
}
